|
|
@@ -5,56 +5,55 @@ require "json"
|
5
|
5
|
module Agents
|
6
|
6
|
class MqttAgent < Agent
|
7
|
7
|
description <<-MD
|
8
|
|
- The MQTT agent allows both publication and subscription to an MQTT topic.
|
|
8
|
+ The MQTT agent allows both publication and subscription to an MQTT topic.
|
9
|
9
|
|
10
|
|
- MQTT is a generic transport protocol for machine to machine communication.
|
|
10
|
+ MQTT is a generic transport protocol for machine to machine communication.
|
11
|
11
|
|
12
|
|
- You can do things like:
|
|
12
|
+ You can do things like:
|
13
|
13
|
|
14
|
|
- * Publish to [RabbitMQ](http://www.rabbitmq.com/mqtt.html)
|
15
|
|
- * Run [OwnTracks, a location tracking tool](http://owntracks.org/) for iOS and Android
|
16
|
|
- * Subscribe to your home automation setup like [Ninjablocks](http://forums.ninjablocks.com/index.php?p=/discussion/661/today-i-learned-about-mqtt/p1) or [TheThingSystem](http://thethingsystem.com/dev/supported-things.html)
|
|
14
|
+ * Publish to [RabbitMQ](http://www.rabbitmq.com/mqtt.html)
|
|
15
|
+ * Run [OwnTracks, a location tracking tool](http://owntracks.org/) for iOS and Android
|
|
16
|
+ * Subscribe to your home automation setup like [Ninjablocks](http://forums.ninjablocks.com/index.php?p=/discussion/661/today-i-learned-about-mqtt/p1) or [TheThingSystem](http://thethingsystem.com/dev/supported-things.html)
|
17
|
17
|
|
18
|
|
- Simply choose a topic (think email subject line) to publish/listen to, and configure your service.
|
|
18
|
+ Simply choose a topic (think email subject line) to publish/listen to, and configure your service.
|
19
|
19
|
|
20
|
|
- It's easy to setup your own [broker](http://jpmens.net/2013/09/01/installing-mosquitto-on-a-raspberry-pi/) or connect to a [cloud service](www.cloudmqtt.com)
|
|
20
|
+ It's easy to setup your own [broker](http://jpmens.net/2013/09/01/installing-mosquitto-on-a-raspberry-pi/) or connect to a [cloud service](www.cloudmqtt.com)
|
21
|
21
|
|
22
|
|
- Hints:
|
23
|
|
- Many services run mqtts (mqtt over SSL) often with a custom certificate.
|
|
22
|
+ Hints:
|
|
23
|
+ Many services run mqtts (mqtt over SSL) often with a custom certificate.
|
24
|
24
|
|
25
|
|
- You'll want to download their cert and install it locally, specifying the ```certificate_path``` configuration.
|
|
25
|
+ You'll want to download their cert and install it locally, specifying the ```certificate_path``` configuration.
|
26
|
26
|
|
27
|
27
|
|
28
|
|
- Example configuration:
|
|
28
|
+ Example configuration:
|
29
|
29
|
|
30
|
|
- <pre><code>{
|
31
|
|
- 'uri' => 'mqtts://user:pass@locahost:8883'
|
32
|
|
- 'ssl' => :TLSv1,
|
33
|
|
- 'ca_file' => './ca.pem',
|
34
|
|
- 'cert_file' => './client.crt',
|
35
|
|
- 'key_file' => './client.key',
|
36
|
|
- 'topic' => 'huginn'
|
37
|
|
- }
|
38
|
|
- </code></pre>
|
39
|
|
-
|
40
|
|
- Subscribe to CloCkWeRX's TheThingSystem instance (thethingsystem.com), where
|
41
|
|
- temperature and other events are being published.
|
|
30
|
+ <pre><code>{
|
|
31
|
+ 'uri' => 'mqtts://user:pass@locahost:8883'
|
|
32
|
+ 'ssl' => :TLSv1,
|
|
33
|
+ 'ca_file' => './ca.pem',
|
|
34
|
+ 'cert_file' => './client.crt',
|
|
35
|
+ 'key_file' => './client.key',
|
|
36
|
+ 'topic' => 'huginn'
|
|
37
|
+ }
|
|
38
|
+ </code></pre>
|
42
|
39
|
|
43
|
|
- <pre><code>{
|
44
|
|
- 'uri' => 'mqtt://kcqlmkgx:sVNoccqwvXxE@m10.cloudmqtt.com:13858'
|
45
|
|
- 'topic' => 'the_thing_system/demo'
|
46
|
|
- }
|
47
|
|
- </code></pre>
|
|
40
|
+ Subscribe to CloCkWeRX's TheThingSystem instance (thethingsystem.com), where
|
|
41
|
+ temperature and other events are being published.
|
48
|
42
|
|
49
|
|
- Subscribe to all topics
|
50
|
|
- <pre><code>{
|
51
|
|
- 'uri' => 'mqtt://kcqlmkgx:sVNoccqwvXxE@m10.cloudmqtt.com:13858'
|
52
|
|
- 'topic' => '/#'
|
53
|
|
- }
|
54
|
|
- </code></pre>
|
|
43
|
+ <pre><code>{
|
|
44
|
+ 'uri' => 'mqtt://kcqlmkgx:sVNoccqwvXxE@m10.cloudmqtt.com:13858'
|
|
45
|
+ 'topic' => 'the_thing_system/demo'
|
|
46
|
+ }
|
|
47
|
+ </code></pre>
|
55
|
48
|
|
56
|
|
- Find out more detail on [subscription wildcards](http://www.eclipse.org/paho/files/mqttdoc/Cclient/wildcard.html)
|
|
49
|
+ Subscribe to all topics
|
|
50
|
+ <pre><code>{
|
|
51
|
+ 'uri' => 'mqtt://kcqlmkgx:sVNoccqwvXxE@m10.cloudmqtt.com:13858'
|
|
52
|
+ 'topic' => '/#'
|
|
53
|
+ }
|
|
54
|
+ </code></pre>
|
57
|
55
|
|
|
56
|
+ Find out more detail on [subscription wildcards](http://www.eclipse.org/paho/files/mqttdoc/Cclient/wildcard.html)
|
58
|
57
|
MD
|
59
|
58
|
|
60
|
59
|
event_description <<-MD
|
|
|
@@ -62,18 +61,7 @@ module Agents
|
62
|
61
|
|
63
|
62
|
<pre><code>{
|
64
|
63
|
"topic": "owntracks/kcqlmkgx/Dan",
|
65
|
|
- "message": {
|
66
|
|
- "topic": "owntracks/kcqlmkgx/Galaxy S3 Dan",
|
67
|
|
- "message": {
|
68
|
|
- "_type": "location",
|
69
|
|
- "lat": "-34.849373",
|
70
|
|
- "lon": "138.5218449",
|
71
|
|
- "tst": "1401761484",
|
72
|
|
- "acc": "10.0",
|
73
|
|
- "batt": "71"
|
74
|
|
- },
|
75
|
|
- "time": 1401771825
|
76
|
|
-},
|
|
64
|
+ "message": {"_type": "location", "lat": "-34.8493644", "lon": "138.5218119", "tst": "1401771049", "acc": "50.0", "batt": "31", "desc": "Home", "event": "enter"},
|
77
|
65
|
"time": 1401771051
|
78
|
66
|
}</code></pre>
|
79
|
67
|
MD
|